using System;
using System.Diagnostics.Contracts;
using Sundstrom.Mvvm.Messaging;

namespace Sundstrom.Mvvm.Tests.ViewModels
{
    public sealed class ViewModel2 : ViewModelBase
    {
        private string _sampleProperty;

        public ViewModel2()
        {
            MessageBus = MessageBus.Default;
            MessageBus.Subscribe<TextMessage>(OnMessageReceived);
        }

        private void OnMessageReceived(TextMessage message)
        {
            Contract.Requires<ArgumentNullException>(message != null);

            SampleProperty = message.Text;
        }

        private MessageBus MessageBus { get; set; }

        public string SampleProperty
        {
            get { return _sampleProperty; }
            set
            {
                _sampleProperty = value;
                RaisePropertyChanged();
            }
        }
    }
}